
var type_info = new Object();

type_info.save = function() {
    var name = $("#varName").val();
    if('' == name){
        layer.msg("类别名称不能为空");
        return;
    }
    if(name.length > 40){
        layer.msg("类别名称超出长度限制");
        return;
    }
    if(type_info.isExistName($.trim(name), $("#id").val())){
        layer.msg("方案类别已存在");
        return;
    }
    if('' == $("#order").val()){
        layer.msg("类别排序不能为空");
        return;
    }
    var params = $("#infoForm").serialize();
    $.ajax({
        url: appPath + '/admin/trainType/save',
        async: false,
        type: 'post',
        data: params,
        success: function(data){
            if("10000" == data.code){
                layer.msg(data.message,{icon:1,time:1000}, function () {
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                    var url = appPath + "/admin/trainType/paging";
                    parent.train_type.initTable(url);
                })
            }else{
                layer.msg(data.message,{icon:2});
            }
        }
    });
}



type_info.isExistName = function (varName, id) {
    var flag = false;
    $.ajax({
        url: appPath + "/admin/trainType/isExistName",
        data: {"varName": varName, "id":id},
        dataType: "json",
        async:false,
        type: "post",
        success: function (data) {
            var result = eval(data).isExistName;
            if (result == "true") {
                flag = true;
            }
        }
    });
    return flag;
}

type_info.close = function() {
    parent.layer.close(parent.layer.getFrameIndex(window.name));
}
